package com.esunny.resourcevisualization.service.impl;

import com.esunny.resourcevisualization.domain.entity.ResourceTypeEntity;
import com.esunny.resourcevisualization.domain.entity.UserEntity;
import com.esunny.resourcevisualization.service.GroupResourceService;
import com.esunny.resourcevisualization.service.ResourceTypeEntityService;
import com.esunny.resourcevisualization.service.UserEntityService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0.0.0
 * @ClassName GroupResourceServiceImpl
 * @Description 获取组资源数据逻辑处理
 * @Author baochencong
 * @Date 2020/11/5 9:37
 */
@Service
public class GroupResourceServiceImpl implements GroupResourceService {

    @Resource
    private UserEntityService userEntityService;

    @Resource
    private ResourceTypeEntityService resourceTypeEntityService;

    @Override
    public List<ResourceTypeEntity> getGroupResourceListByUserGroupNameAndResourceTypeName(String userGroupName, String name) {
        List<ResourceTypeEntity> entityList = new ArrayList<>();

        List<UserEntity> userEntityList = userEntityService.getUserEntityListByUserGroupName(userGroupName);
        for (UserEntity eachUserEntity : userEntityList) {
            ResourceTypeEntity resourceTypeEntity = resourceTypeEntityService.getResourceTypeEntityByEntityIdAndName(eachUserEntity.getEntityId(), name);
            if (resourceTypeEntity != null) {
                entityList.add(resourceTypeEntity);
            }
        }
        return entityList;
    }
}
